package Oct_2020_BETA.part6;

public class Oct_Thread {
    public static void main(String[] args) throws InterruptedException {
        /*Thread thread=new Thread();
        System.out.println(thread.getName());
        System.out.println(thread.getId());
        thread.setName("Joker");
        thread.run();
        thread.start();
        thread.stop();
        Thread.sleep(10000);
        Thread now=Thread.currentThread();*/

        /*MyThread myThread = new MyThread();
        MyThread myThread1 = new MyThread();
        myThread1.start();
        myThread.start();*///并发
//        start是启动状态，run只是方法调用;来源于CPU的状态切换
//        新建-运行-阻塞
        MyRunnable myRunnable=new MyRunnable();
        Thread t=new Thread(myRunnable);
        MyRunnable myRunnable1=new MyRunnable();
        Thread t1=new Thread(myRunnable1);
        t1.start();
        t.start();
//       继承Runnable接口：灵活，可以再继承其他类，但使用起来比较麻烦
//        继承Thread类:使用Thread类的方法时很快捷,但不能再继承其他类
    }
}

class MyThread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(this.getName() + "--" + i);
        }
    }
}
class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i=0;i<100;i++){
            System.out.println(Thread.currentThread().getName()+"--"+i);
        }
    }
}
